package com.central.operate.controller;

import com.central.model.common.PageResult;
import com.central.operate.model.LoginCreateTime;
import com.central.operate.model.LoginInfo;
import com.central.operate.service.RegisterService;
import com.central.operate.vo.LoginCountVO;
import com.central.operate.vo.RegisterCountChartVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 注册量控制类
 */
@Slf4j
@RestController
public class RegisterConterller {

    @Autowired
    private RegisterService registerService;


    @PreAuthorize("hasAuthority('operate:get/loginRegister')")
    @ApiOperation(value = "玩家具体注册时间")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"), @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")})
    @GetMapping("/loginRegister")
    public PageResult<LoginInfo> getSpecificRegisterTime(@RequestParam Map<String, Object> params) {
        params.forEach((k, v) -> log.info(k + ":" + v));
        return registerService.getSpecificRegisterTime(params);
    }

    /**
     * 按天显示注册量
     *
     * @param params
     * @return
     */
    /*@PreAuthorize("hasAuthority('operate:get/loginRegister')")
    @ApiOperation(value = "玩家注册量")
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "分页起始位置", required = true, dataType = "Integer"), @ApiImplicitParam(name = "limit", value = "分页结束位置", required = true, dataType = "Integer")})
    @GetMapping("/registerCount")
    public PageResult<LoginCreateTime> getRegister(@RequestParam Map<String, Object> params) {
        params.forEach((k, v) -> log.info(k + ":" + v));
        return registerService.findLoginRegister(params);
    }*/
    @PreAuthorize("hasAuthority('operate:get/register')")
    @ApiOperation(value = "玩家注册量:图表")
    @GetMapping("/registerCount")
    public List<RegisterCountChartVO> getRegisterChart(@RequestParam Map<String, Object> params) {
        Long s = new Date().getTime();
        log.info("传入时间" + params);
        params.forEach((k, v) -> log.info(k + " : " + v));
        List<RegisterCountChartVO> record = registerService.listRegisterCount(params);
        System.out.println("耗时:" + (new Date().getTime() - s));
        return record;
    }

}
